#include <bits/stdc++.h>
#define MAXN 0x3f3f3f
using namespace std;
bool del[MAXN] = {false};
int NEXT[MAXN];
int main()
{
    int n, m, head = 1;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) NEXT[i] = i + 1;        // 形成单向链表
    NEXT[n] = head;                                     // 形成循环链表
    int cnt = n, pre = n, cur = head;
    while(cnt != 1)
    {
        // 将cur定位到报出m的元素上
        for(int i = 1; i < m; ++i)
            pre = cur, cur = NEXT[cur];
        // 删除n
        // cout << cur << endl;
        NEXT[pre] = NEXT[cur];
        cnt -= 1;
        cur = NEXT[pre];
    }
    cout <<  NEXT[pre] << endl;
    return 0;
}